<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 函数节流
        // 1. 函数节流：在N秒内只执行一次函数
        function throttle(fn, delay) {
            var context, args;
            var previous = 0;
            return function() {
                var now = +new Date();
                context = this;
                args = arguments;
                if (now - previous >= delay) {
                    fn.apply(context, args);
                    previous = now;
                }
            }
        }
        // 使用
        window.onresize = throttle(function() {
            console.log(1);
        }, 1000)
    </script>
</body>
</html>